﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SweeperPrototype.Business.Fields;
using SweeperPrototype.Business.Keys;

namespace SweeperPrototype.Objects
{
	public partial class EffectiveExposure
	{
        public class UniqueKey
        {
            private BookCode m_BookCode;
            private ExposureRIC m_ExposureRIC;
            private EffectiveRIC m_EffectiveRIC;

            public UniqueKey( EffectiveExposure exposure )
                : this( exposure.BookCode, exposure.ExposureRIC, exposure.EffectiveRIC ){}

            public UniqueKey(BookCode book_code, ExposureRIC exposure_ric, EffectiveRIC effective_ric)
            {
                m_BookCode = book_code;
                m_ExposureRIC = exposure_ric;
                m_EffectiveRIC = effective_ric;
            }

            public BookCode BookCode
            {
                get { return m_BookCode; }
            }

            public ExposureRIC ExposureRIC
            {
                get { return m_ExposureRIC; }
            }

            public EffectiveRIC EffectiveRIC
            {
                get { return m_EffectiveRIC; }
            }


            public static bool operator ==(UniqueKey lhs, UniqueKey rhs)
            {
                if (ReferenceEquals(null, lhs)) return false;
                if (ReferenceEquals(null, rhs)) return false;

                return lhs.Equals(rhs);
            }

            public static bool operator !=(UniqueKey lhs, UniqueKey rhs)
            {
                return !(lhs == rhs);
            }

            public bool Equals(UniqueKey other)
            {
                if (ReferenceEquals(null, other)) return false;
                if (ReferenceEquals(this, other)) return true;
                return Equals(other.m_BookCode, m_BookCode) && Equals(other.m_ExposureRIC, m_ExposureRIC) && Equals(other.m_EffectiveRIC, m_EffectiveRIC);
            }

            public override bool Equals(object obj)
            {
                if (ReferenceEquals(null, obj)) return false;
                if (ReferenceEquals(this, obj)) return true;
                if (obj.GetType() != typeof (UniqueKey)) return false;
                return Equals((UniqueKey) obj);
            }

            public override int GetHashCode()
            {
                unchecked
                {
                    int result = (m_BookCode != null ? m_BookCode.GetHashCode() : 0);
                    result = (result*397) ^ (m_ExposureRIC != null ? m_ExposureRIC.GetHashCode() : 0);
                    result = (result*397) ^ (m_EffectiveRIC != null ? m_EffectiveRIC.GetHashCode() : 0);
                    return result;
                }
            }
        }
	}
}
